﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using XQ.AssetsBonus.BLL.BonusManage;
using XQ.AssetsBonus.DAL;
using XQ.AssetsBonus.DAL.Bonus.Model;
using XQ.AssetsBonus.WebAPI.Models;

namespace XQ.AssetsBonus.WebAPI.Controllers.BonusManage
{
    public class BonusManageController : ApiController
    {
        private readonly BonusManageBLL bll = new BonusManageBLL();
        /// <summary>
        /// 保存  新增
        /// </summary>
        /// <param name="detail"></param>
        /// <returns></returns>
        [Route("Api/BonusManage/save")]
        public ResultModel save(BonusBatch detail)
        {
            ResultModel resultModel = new ResultModel();
            try
            {
                resultModel.data = bll.save(detail);
            }
            catch (Exception ex)
            {
                resultModel.success = false;
                resultModel.code = "10001";
                resultModel.message = "执行失败";
                resultModel.data = ex.Message;
            }
            return resultModel;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        [Route("Api/BonusManage/delete")]
        public ResultModel delete(List<int> item)
        {
            ResultModel resultModel = new ResultModel();
            try
            {
                resultModel.data = bll.delete(item);
            }
            catch (Exception ex)
            {
                resultModel.success = false;
                resultModel.code = "10001";
                resultModel.message = "执行失败";
                resultModel.data = ex.Message;
            }
            return resultModel;
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="bonusSearchModel"></param>
        /// <returns></returns>
        [Route("Api/BonusManage/Search")]
        public ResultModel Search(BonusSearchModel bonusSearchModel)
        {
            ResultModel resultModel = new ResultModel();
            try
            {
                resultModel.data = bll.Search(bonusSearchModel);
            }
            catch (Exception ex)
            {
                resultModel.success = false;
                resultModel.code = "10001";
                resultModel.message = "执行失败";
                resultModel.data = ex.Message;
            }
            return resultModel;
        }

        /// <summary>
        /// 编辑 获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("Api/BonusManage/GetBonusById")]
        public ResultModel GetBonusById(int id)
        {
            ResultModel resultModel = new ResultModel();
            try
            {
                resultModel.data = bll.GetBonusById(id);
            }
            catch (Exception ex)
            {
                resultModel.success = false;
                resultModel.code = "10001";
                resultModel.message = "执行失败";
                resultModel.data = ex.Message;
            }
            return resultModel;
        }
    }
}
